package com.bienvenue.main.ui.activity.personal;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.bienvenue.main.R;
import com.bienvenue.main.base.BaseActivity;
import com.bienvenue.main.httpService.ResponseObserver;
import com.bienvenue.main.model.HttpBean;
import com.bienvenue.main.model.JobPostModel;
import com.bienvenue.main.model.ResumeInfoModel;
import com.bienvenue.main.model.SaveResumeModel;
import com.bienvenue.main.serviceApi.ServiceModel;
import com.bienvenue.main.ui.activity.enterprise.PostJobActivity;
import com.bienvenue.main.utils.SPUtils;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 　　　　　　　 ┏┓       ┏┓+ +
 * 　　　　　　　┏┛┻━━━━━━━┛┻┓ + +
 * 　　　　　　　┃　　　　　　 ┃
 * 　　　　　　　┃　　　━　　　┃ ++ + + +
 * 　　　　　　 █████━█████  ┃+
 * 　　　　　　　┃　　　　　　 ┃ +
 * 　　　　　　　┃　　　┻　　　┃
 * 　　　　　　　┃　　　　　　 ┃ + +
 * 　　　　　　　┗━━┓　　　 ┏━┛
 * ┃　　  ┃
 * 　　　　　　　　　┃　　  ┃ + + + +
 * 　　　　　　　　　┃　　　┃　Code is far away from     bug with the animal protecting
 * 　　　　　　　　　┃　　　┃ + 　　　　         神兽保佑,代码无bug
 * 　　　　　　　　　┃　　　┃
 * 　　　　　　　　　┃　　　┃　　+
 * 　　　　　　　　　┃　 　 ┗━━━┓ + +
 * 　　　　　　　　　┃ 　　　　　┣┓
 * 　　　　　　　　　┃ 　　　　　┏┛
 * 　　　　　　　　　┗┓┓┏━━━┳┓┏┛ + + + +
 * 　　　　　　　　　 ┃┫┫　 ┃┫┫
 * 　　　　　　　　　 ┗┻┛　 ┗┻┛+ + + +
 *
 * @ProjectName: Bienvenue
 * @Package: com.bienvenue.main.ui.activity
 * @ClassName: CareerObjectiveActivity
 * @Description: 求职意向
 * @Author: Mr.Chen
 * @UpdateUser: Mr.Chen
 * @UpdateDate: 2020/9/16
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class CareerObjectiveActivity extends BaseActivity {

    @BindView(R.id.tv_dream_position_money)
    TextView tvDreamPositionMoney;//期望薪资
    @BindView(R.id.tv_dream_position)
    TextView tvDreamPosition;//期望岗位
    @BindView(R.id.tv_dream_position_address)
    TextView tvDreamPositionAddress;//期望城市
    @BindView(R.id.tv_dream_position_date)
    TextView tvDreamPositionDate;//到岗时间
    @BindView(R.id.tv_delete_btn)
    TextView tvDeleteBtn;

    List<String> stringList = new ArrayList<>();
    String userId;
    int type;
    ResumeInfoModel.DataBean.UResumeJobhuntingBean bean;

    @Override
    protected void initData() {
        userId = SPUtils.getString("userId");
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            type = bundle.getInt("type");
            bean = bundle.getParcelable("positionMoney");
            if (type == 1) {
                tvDeleteBtn.setVisibility(View.VISIBLE);
                tvDreamPositionMoney.setText(bean.getSalary());
                tvDreamPosition.setText(bean.getPosition());
                tvDreamPositionAddress.setText(bean.getArea());
                tvDreamPositionDate.setText(bean.getArrival());
            } else {
                tvDeleteBtn.setVisibility(View.GONE);
            }
        }

    }

    @Override
    protected void initView() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_career_objective;
    }

    @OnClick(R.id.iv_return_btn)
    void onFinish() {
        this.finish();
    }

    @OnClick(R.id.tv_save_btn)
    void onSave() {
        if ("请选择薪资要求".equals(tvDreamPositionMoney.getText().toString().trim())) {
            showToast("请选择薪资要求");
            return;
        } else if ("请选择期望岗位".equals(tvDreamPosition.getText().toString().trim())) {
            showToast("请选择期望岗位");
            return;
        } else if ("请选择城市".equals(tvDreamPositionAddress.getText().toString().trim())) {
            showToast("请选择城市");
            return;
        } else if ("请选择到岗时间".equals(tvDreamPositionDate.getText().toString().trim())) {
            showToast("请选择到岗时间");
            return;
        } else if (TextUtils.isEmpty(userId) || userId.equals("")) {
            showToast("信息错误，请重新登录");
        }
        SaveResumeModel.JobHuntingModel model = new SaveResumeModel.JobHuntingModel();
        model.setArea(tvDreamPositionAddress.getText().toString().trim());
        model.setArrival(tvDreamPositionDate.getText().toString().trim());
        model.setPosition(tvDreamPosition.getText().toString().trim());
        model.setSalary(tvDreamPositionMoney.getText().toString().trim());
        model.setUserid(userId);
        model.setId(bean.getId());

        ServiceModel.getServiceModel().onSaveResumeJobHunting(model, new ResponseObserver<HttpBean>() {
            @Override
            public void onSuccess(HttpBean response) {
                if (response.getCode() == 200) {
                    showToast(response.getMsg());
                    CareerObjectiveActivity.this.finish();
                } else {
                    showToast(response.getMsg());
                }

            }

            @Override
            public void onFail(String message) {
                showLog(message);
            }
        });
    }

    @OnClick(R.id.ll_dream_position)
    void onDreamPosition() {
        showToast("期望岗位");
        tvDreamPosition.setText("Java");
    }

    @OnClick(R.id.ll_dream_position_address)
    void onDreamPositionAddress() {
        showToast("请选择城市");
        tvDreamPositionAddress.setText("西安");
    }


    @OnClick(R.id.ll_dream_position_money)
    void onDreamPositionMoney() {
        ServiceModel.getServiceModel().getListByTypePositionSalary(new ResponseObserver<JobPostModel>() {
            @Override
            public void onSuccess(JobPostModel response) {
                if (response.getCode() == 200) {
                    if (stringList != null && stringList.size() > 0) {
                        stringList.clear();
                    }
                    for (int i = 0; i < response.getData().size(); i++) {
                        stringList.add(response.getData().get(i).getVal());
                    }
                    OptionsPickerView pvOptions = new OptionsPickerBuilder(CareerObjectiveActivity.this, new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            //返回的分别是三个级别的选中位置
                            if (response.getData().get(options1).getVal().equals(stringList.get(options1))) {
                            }
                            tvDreamPositionMoney.setText(stringList.get(options1));

                        }
                    })
                            .setTitleText("请选择薪资")
                            .setDividerColor(Color.BLACK)
                            .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                            .setContentTextSize(20)
                            .build();
                    pvOptions.setPicker(stringList);
                    pvOptions.show();

                } else {
                    showToast(response.getMsg());
                }
            }

            @Override
            public void onFail(String message) {
                Log.e("TAG", message);

            }
        });
    }

    @OnClick(R.id.ll_dream_position_date)
    void onDreamPositionDate() {
        ServiceModel.getServiceModel().getListByTimeArrival(new ResponseObserver<JobPostModel>() {
            @Override
            public void onSuccess(JobPostModel response) {
                if (response.getCode() == 200) {
                    if (stringList != null && stringList.size() > 0) {
                        stringList.clear();
                    }
                    for (int i = 0; i < response.getData().size(); i++) {
                        stringList.add(response.getData().get(i).getVal());
                    }
                    OptionsPickerView pvOptions = new OptionsPickerBuilder(CareerObjectiveActivity.this, new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            //返回的分别是三个级别的选中位置
                            if (response.getData().get(options1).getVal().equals(stringList.get(options1))) {
                            }
                            tvDreamPositionDate.setText(stringList.get(options1));
                        }
                    })
                            .setTitleText("请选择到岗时间")
                            .setDividerColor(Color.BLACK)
                            .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                            .setContentTextSize(20)
                            .build();
                    pvOptions.setPicker(stringList);
                    pvOptions.show();

                } else {
                    showToast(response.getMsg());
                }
            }

            @Override
            public void onFail(String message) {
                showLog(message);

            }
        });
    }

    @OnClick(R.id.tv_delete_btn)
    void onDelete() {
        ServiceModel.getServiceModel().deleteResumeJobHunting(bean.getId(), new ResponseObserver<HttpBean>() {
            @Override
            public void onSuccess(HttpBean response) {
                if (response.getCode() == 200) {
                    showToast(response.getMsg());
                    CareerObjectiveActivity.this.finish();
                } else {
                    showToast(response.getMsg());
                }
            }

            @Override
            public void onFail(String message) {
                showLog(message);
            }
        });

    }
}
